package org.dna.wicketui.issues;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.tigris.scarab.model.Issue;
//import org.dna.metronomo.persistence.Job;

/**
 * Displays the list of jobs passed into, invoked by a details link in the activities
 * list panel.
 * */
public class IssueListPanel extends Panel {

    private static final long serialVersionUID = 7273740355903637758L;
    private static final int ITEM_PER_PAGE = 20;

    PageableListView<Issue> m_issuesView;
    IModel<List<Issue>> m_issues;

    @SuppressWarnings({"serial", "unchecked"})
    public IssueListPanel(String id, IModel<List<Issue>> issues) {
        super(id);
        m_issues = issues;
        initComponents(issues);
    }

     private void initComponents(IModel<List<Issue>> issues) {
        m_issuesView = new PageableListView<Issue>("issues", issues, ITEM_PER_PAGE) {

            @Override
            protected void populateItem(ListItem<Issue> item) {
                Issue issue = item.getModelObject();
                item.setModel(new CompoundPropertyModel<Issue>(issue));
//TODO re-enable the navigation from issue list to issue details
//                Link link = new Link("link", issueModel) {
//
//                    @Override
//                    public void onClick() {
//                        setResponsePage(new ManageIssuePage(issue));
//                    }
//                };
//                link.add(new Label("name"));
//                item.add(link);
//                item.add(new MultiLineLabel("description"));
                item.add(new Label("emailReferences"));
                // // item.add(new DeleteLink("delete", item.getModel()));
            }
        };
        add(m_issuesView);
        add(new PagingNavigator("navigator", m_issuesView));
     }
}
